﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// BasePage 的摘要说明
/// </summary>
public class BasePage : System.Web.UI.Page
{
    public BasePage()
    {
        //
        // TODO: 在此处添加构造函数逻辑
        //
    }

    public string toLanguage = "English Version";

    protected override void InitializeCulture()
    {
        if (Request.Cookies["Language"] != null &&
            Request.Cookies["Language"].Value != null && Request.Cookies["Language"].Value != "")
        {
            setCulture();
        }
        else
        { //设置Cookie
            Response.Cookies["Language"].Value =
              (Request.Headers["accept-language"].Split(",".ToCharArray())[0]);
            Response.Cookies["Language"].Expires = DateTime.Now.AddDays(1000);
            setCulture();
        }
        base.InitializeCulture();
    }

    private void setCulture()
    {
        try
        {
            String selectedLanguage = Request.Cookies["Language"].Value;
            UICulture = selectedLanguage;
            Culture = selectedLanguage;

            System.Threading.Thread.CurrentThread.CurrentCulture =
              System.Globalization.CultureInfo.CreateSpecificCulture(selectedLanguage);
            System.Threading.Thread.CurrentThread.CurrentUICulture = new
              System.Globalization.CultureInfo(selectedLanguage);

            if (selectedLanguage.Contains("en"))
            {
                toLanguage = "中 文 版";
            }
            else
            {
                toLanguage = "English Version";
            }
        }
        catch
        {
            Response.Cookies.Clear();
        }
    }

}
